package com.systop.ltbook.order.service;

import java.util.Date;
import java.util.List;

import org.apache.commons.lang.time.DateUtils;
import org.springframework.stereotype.Service;

import com.ibm.icu.text.SimpleDateFormat;
import com.systop.core.service.BaseGenericsManager;
import com.systop.ltbook.order.model.OrderForm;

@Service
public class OrderFormManager extends BaseGenericsManager<OrderForm> {
	/**
	 * 得到下一个sn号
	 * 
	 * @return
	 */
	public String getNextSn() {
		int count;
		// 查询当天已有记录数
		String hql = "from OrderForm oForm where oForm.createDate > ? ";
		List<OrderForm> list = query(hql, DateUtils.addDays(new Date(), -1));

		count = list.size();
		count++;

		StringBuffer buf = new StringBuffer();
		SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
		buf.append(sf.format(new Date()));
		buf.append(String.format(String.valueOf(count)));

		return buf.toString();
	}

}
